Add ForagerBehavior example — GSoC 2026 behavioral framework prototype#392
Add ForagerBehavior example — GSoC 2026 behavioral framework prototype#3921khaled-ctrl wants to merge 14 commits intomesa:mainfrom
Conversation
for more information, see https://pre-commit.ci
|
Thanks! Can you do a self-review and then request a peer review, following: |
1khaled-ctrl
left a comment
There was a problem hiding this comment.
Self-review complete. Code is clean and tested locally.
|
Hi @EwoutH — self-review is complete. Code is clean and tested locally. |
examples/ForagerBehavior/model.py
Outdated
| import mesa | ||
|
|
||
|
|
||
| class ForagerAgent(mesa.Agent): |
There was a problem hiding this comment.
You might want to use appropriate agent class from discrete_space
examples/ForagerBehavior/model.py
Outdated
| resource_density=0.3, | ||
| ): | ||
| super().__init__() | ||
| self.grid = mesa.space.MultiGrid(width, height, torus=True) |
There was a problem hiding this comment.
mesa.space has been removed for 4.0, Use mesa.discrete_space instead
| for y in range(height): | ||
| if self.random.random() < resource_density: | ||
| self.resources[(x, y)] = 20.0 | ||
| for _ in range(n_agents): |
There was a problem hiding this comment.
You might want to use create_agents method instead
examples/ForagerBehavior/README.md
Outdated
| ## How to Run | ||
| ```bash | ||
| pip install mesa | ||
| python run_simulation.py |
There was a problem hiding this comment.
I couldn't find run_simulation.py
There was a problem hiding this comment.
I couldn't find
run_simulation.py
Good catch! I will switch to the appropriate agent class from discrete_space.
|
Hey, cool concept! A few things to fix though:
Fix the crashes first and it'll be in much better shape! |
Updated instructions to run the simulation with Solara.
Updated the 'How to Run' section formatting in README.
Added instructions for running the ForagerBehavior example.
|
Hi @EwoutH @codebreaker32 @Harshini2411 — I have addressed all the feedback:
Ready for re-review. Thank you! |
for more information, see https://pre-commit.ci
|
The Mesa 4 fixes look good! One thing still outstanding though the README still mentions StateMachine, BehaviorModules, EnergyDepletionBehavior etc. which don't exist in the code. Just update it to describe what the model actually does and it's ready! |
What this adds
A new example demonstrating a modular behavioral framework for Mesa agents.
ForagerBehavior model
Agents switch between behavioral states:
Transition logic:
Files added
model.py— ForagerAgent and ForagerModelapp.py— SolaraViz visualization with slidersREADME.md— explanation and usage guideContext
This example is part of my GSoC 2026 proposal:
Behavioral Framework for Agent Models in Mesa
The full prototype is at:
https://github.com/1khaled-ctrl/mesa-behavior-framework-prototype
— Khaled Saber